package com.km.controller;

import com.km.entity.DingdingMsgEntity;
import com.km.service.DingdingMsgService;
import com.km.utils.PageUtils;
import com.km.utils.Query;
import com.km.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-06-19 17:54:03
 */
@RestController
@RequestMapping("dingdingmsg")
public class DingdingMsgController {
    @Autowired
    private DingdingMsgService dingdingMsgService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("dingdingmsg:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DingdingMsgEntity> dingdingMsgList = dingdingMsgService.queryList(query);
        int total = dingdingMsgService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(dingdingMsgList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("dingdingmsg:info")
    public R info(@PathVariable("id") Long id) {
        DingdingMsgEntity dingdingMsg = dingdingMsgService.queryObject(id);

        return R.ok().put("dingdingMsg", dingdingMsg);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dingdingmsg:save")
    public R save(@RequestBody DingdingMsgEntity dingdingMsg) {
        dingdingMsgService.save(dingdingMsg);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dingdingmsg:update")
    public R update(@RequestBody DingdingMsgEntity dingdingMsg) {
        dingdingMsgService.update(dingdingMsg);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dingdingmsg:delete")
    public R delete(@RequestBody Long[] ids) {
        dingdingMsgService.deleteBatch(ids);

        return R.ok();
    }

}
